package com.daluzy.chmanager.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.daluzy.chmanager.R;
import com.daluzy.chmanager.activity.TestPointInfoActivity;
import com.daluzy.chmanager.bean.TestPoint;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TestPointAdapter extends RecyclerView.Adapter<TestPointAdapter.MyViewHolder> {

    private Context context;
    private List<TestPoint> myData = new ArrayList<>();

    public TestPointAdapter(Context context, List<TestPoint> myData) {
        this.context = context;
        this.myData = myData;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.adapter_test_point_item_daluzy, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        TestPoint testPoint = myData.get(position);
        holder.tvPointName.setText(testPoint.getPoint_name());
        if (!TextUtils.isEmpty(testPoint.getTest_person_name()))
            holder.tvTestPerson.setText(testPoint.getTest_person_name());
        holder.tvPointTem.setText(testPoint.getPoint_tem());

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, TestPointInfoActivity.class);
                intent.putExtra("testPointId",testPoint.getObjectId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return myData.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_point_name)
        TextView tvPointName;
        @BindView(R.id.tv_point_tem)
        TextView tvPointTem;
        @BindView(R.id.tv_test_person)
        TextView tvTestPerson;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
